package com.zk.algorithm.linkedlist;

import com.zk.algorithm.annotation.LeetCode;
import com.zk.algorithm.annotation.Medium;
import com.zk.algorithm.bean.ListNode;

/**
 * 链表交换相邻元素
 */
@Medium
@LeetCode("24")
public class SwapNodesInPairs {

    // ===========================
    // 递归解法
    // ===========================

    public ListNode swapPairs(ListNode head) {
        if ((head == null) || (head.next == null))
            return head;

        ListNode n = head.next;
        head.next = swapPairs(head.next.next);
        n.next = head;

        return n;
    }

}
